# app/api/rag/schemas.py

from typing import List, Dict, Any, Optional
from pydantic import BaseModel, Field

class QuestionRequest(BaseModel):
    """问题请求模型"""
    question: str = Field(..., description="用户问题", min_length=1, max_length=1000)
    conversation_id: Optional[str] = Field(None, description="会话ID")
    include_images: bool = Field(True, description="是否包含图片召回结果")
    top_k: int = Field(10, description="召回数量", ge=1, le=50)
    knowledge_base: str = Field("default", description="知识库名称")

class SourceInfo(BaseModel):
    """来源信息模型"""
    index: int = Field(..., description="序号")
    content: str = Field(..., description="内容片段")
    score: float = Field(..., description="相似度分数")
    source: str = Field(..., description="来源文件")
    file_type: str = Field(..., description="文件类型")
    page_num: Optional[int] = Field(None, description="页码（PDF）")
    slide_num: Optional[int] = Field(None, description="幻灯片编号（PPT）")
    paragraph_num: Optional[int] = Field(None, description="段落编号（DOC）")

class ImageSourceInfo(BaseModel):
    """图片来源信息模型"""
    index: int = Field(..., description="序号")
    image_path: str = Field(..., description="图片路径")
    filename: str = Field(..., description="文件名")
    score: float = Field(..., description="相似度分数")
    source: str = Field(..., description="来源文件")
    file_type: str = Field(..., description="文件类型")
    timestamp: Optional[float] = Field(None, description="时间戳（秒，视频）")
    frame_index: Optional[int] = Field(None, description="帧索引（视频）")

class IntentInfo(BaseModel):
    """意图信息模型"""
    intent_type: str = Field(..., description="意图类型")
    description: str = Field(..., description="意图描述")
    weights: Dict[str, float] = Field(default_factory=dict, description="权重配置")

class UserLevelInfo(BaseModel):
    """用户水平信息模型"""
    user_level: str = Field(..., description="用户水平")
    response_style: str = Field(..., description="回答风格")
    content_preference: str = Field(..., description="内容偏好")
    description: str = Field(..., description="水平描述")
    weights: Dict[str, float] = Field(default_factory=dict, description="权重配置")

class RAGResponse(BaseModel):
    """RAG响应模型"""
    answer: str = Field(..., description="回答内容")
    text_sources: List[SourceInfo] = Field(default_factory=list, description="文本来源")
    image_sources: List[ImageSourceInfo] = Field(default_factory=list, description="图片来源")
    knowledge_files: List[str] = Field(default_factory=list, description="使用的知识库文件")
    intent_info: Optional[IntentInfo] = Field(None, description="意图识别信息")
    user_level_info: Optional[UserLevelInfo] = Field(None, description="用户水平信息")

class RAGStats(BaseModel):
    """RAG统计模型"""
    total_questions: int = Field(..., description="总问题数")
    total_answers: int = Field(..., description="总回答数")
    avg_response_time: float = Field(..., description="平均响应时间(秒)")
    success_rate: float = Field(..., description="成功率")

class ConversationHistory(BaseModel):
    """对话历史模型"""
    conversation_id: str = Field(..., description="会话ID")
    messages: List[Dict[str, Any]] = Field(default_factory=list, description="消息列表")
    created_at: str = Field(..., description="创建时间")
    updated_at: str = Field(..., description="更新时间") 